<template>
  <div id="app">
    <nav>
      <router-link to="/">首页</router-link> |
      <router-link to="/games">游戏大厅</router-link> |
      <router-link to="/profile">个人中心</router-link>
      <el-button v-if="isLoggedIn" @click="handleLogout" type="text">退出登录</el-button>
    </nav>
    <router-view/>
  </div>
</template>

<script>
export default {
  name: 'App',
  computed: {
    isLoggedIn() {
      return !!localStorage.getItem('token')
    }
  },
  methods: {
    async handleLogout() {
      try {
        await this.$http.post('/user/logout')
        localStorage.removeItem('token')
        localStorage.removeItem('user')
        this.$message.success('退出成功')
        this.$router.push('/login')
      } catch (error) {
        console.error('Logout error:', error)
        this.$message.error('退出失败')
      }
    }
  }
}
</script>

<style>
#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
  margin-top: 60px;
}

nav {
  padding: 30px;
}

nav a {
  font-weight: bold;
  color: #2c3e50;
  text-decoration: none;
  margin-right: 10px;
}

nav a.router-link-exact-active {
  color: #42b983;
}

nav .el-button {
  margin-left: 20px;
}
</style> 